﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AdministracionCooperativa.Formularios;
using AdministracionCooperativa.Reportes;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

namespace AdministracionCooperativa.Formularios
{
    public partial class Frmrp : Form
    {
        ReportClass reporte = null;
        private void desactivapaleneles()
        {
            GB1.Enabled = false;
            GB2.Enabled = false;
            rbuni.Checked = true;
            GB3.Enabled = false;
            GB4.Enabled = false;
            GB5.Enabled = false;
            GB1.BackColor = Color.FromArgb(255, 70, 13);
            GB2.BackColor = Color.FromArgb(255, 70, 13);
            GB3.BackColor = Color.FromArgb(255, 70, 13);
            GB4.BackColor = Color.FromArgb(255, 70, 13);
            GB5.BackColor = Color.FromArgb(255, 70, 13);
            mes.Text = "";
            mes2.Text = "";
            año.Text = "";
        }
        public Frmrp()
        {
            InitializeComponent();
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void EstableceParametros()
        {
            reporte = null;
           
            if (rB1.Checked)
            {
                var f = dateTimePicker1.Value;
                var fa = "" + f.Year + f.Month + f.Day.ToString("D2");
                reporte = new Deudas();
                reporte.Refresh();
                reporte.SetParameterValue("Fecha1", fa);
            }
            else
                if (rB2.Checked)
                {
                    var f = dateTimePicker2.Value;
                    var fa = "" + f.Year + f.Month + f.Day.ToString("D2");
                    reporte = new Diario();
                    reporte.Refresh();
                    reporte.SetParameterValue("Fecha", fa);
                    
                }
                else
                    if (rB3.Checked)
                    {
                        var f = DateTime.Today;
                        var mes1 = mes.SelectedIndex+1;
                        var f1 = "" + f.Year + mes1.ToString("D2") + "01";
                        var f2 = "" + f.Year + mes1.ToString("D2") + DateTime.DaysInMonth(f.Year, mes1);
                        reporte = new Licencia();
                        reporte.Refresh();
                        reporte.SetParameterValue("Fecha", f1);
                        reporte.SetParameterValue("Fecha1", f2);

                    }
            reporte.DataSourceConnections[0].SetConnection("bdCombis", "combis", "root", "root");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            EstableceParametros();
            if (reporte!=null)
            {
                button1.Enabled = false;
                label7.Text = "Procesando Solicitud....espere";
                rptvisor vista = new rptvisor();
                vista.crystalReportViewer1.ReportSource = null;
                vista.crystalReportViewer1.RefreshReport();
                vista.MdiParent = this.MdiParent;
                vista.crystalReportViewer1.Refresh();
                vista.crystalReportViewer1.ReportSource = reporte;
                vista.crystalReportViewer1.Show();
                vista.Show();
                label7.Text = "";
                button1.Enabled = true;
            }
         
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void Frmrp_Load(object sender, EventArgs e)
        {
            desactivapaleneles();
        }

        private void rB1_CheckedChanged(object sender, EventArgs e)
        {
            desactivapaleneles();
            GB1.Enabled = true;
            GB1.BackColor = Color.FromArgb(255, 113, 13);
           
            
        }

        private void rB2_CheckedChanged(object sender, EventArgs e)
        {
            desactivapaleneles();
            GB2.Enabled = true;
            GB2.BackColor = Color.FromArgb(255, 113, 13);
        }

        private void rB3_CheckedChanged(object sender, EventArgs e)
        {
            desactivapaleneles();
            GB3.Enabled = true;
            GB3.BackColor = Color.FromArgb(255, 113, 13);
        }

        private void rB4_CheckedChanged(object sender, EventArgs e)
        {
            desactivapaleneles();
            GB4.Enabled = true;
            GB4.BackColor = Color.FromArgb(255, 113, 13);
        }

        private void rB5_CheckedChanged(object sender, EventArgs e)
        {
            desactivapaleneles();
            GB5.Enabled = true;
            GB5.BackColor = Color.FromArgb(255, 113, 13);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
        }
        private void dateTimePicker1_Leave(object sender, EventArgs e)
        {
     
        }
    }
}
